// pages/save/save.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    img: '',
  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let uploadImg = wx.getStorageSync('uploadImg')
    let chooseImg = wx.getStorageSync('chooseImg')
    let context = wx.createCanvasContext('myAvatar', this);
    context.lineJoin = "round";
    context.lineWidth = 20;
    context.clearRect(0, 0, 200, 200)
    context.drawImage(uploadImg, 0, 0, 200, 200);
    context.draw(true);
    context.save();
    context.drawImage('/static/image/'+chooseImg, 0, 0, 200, 200);
    context.draw(true);
    context.save(); 
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: "@微信官方，给我2021国庆的国旗渐变头像",
      desc: "领取你的国庆头像，为祖国加油",
      imageUrl: "/static/image/share_img.png",
      path: "/pages/index/index",
      success: function (e) {
        console.log(e);
      },
    };
  },

  onShareTimeline: function () {
    return {
      title: "@微信官方，给我2021国庆的国旗渐变头像",
      desc: "领取你的国庆头像，为祖国加油",
      imageUrl: "/static/image/share_img.png",
      path: "/pages/index/index",
      success: function (e) {
        console.log(e);
      },
    };
  },

  // 返回
  handleBack() {
    wx.redirectTo({
      url: '/pages/index/index',
    })
  },

  handleShare() {
    wx.redirectTo({
      url: '/pages/share/share',
    })
  }
})